<?php
class ImgcateAction extends CommonAction {
	function index(){
		$this->listmap = array();
		if(session(C('USER_AUTH_KEY') ) != 1){
		    $this->listmap['user_id'] = session(C('USER_AUTH_KEY'));
		}else{
			$this->listmap['site_id'] = 0;
		}
		if(isset($_GET['pid'])){
			$this->listmap['pid'] = $this->_get('pid');
			$this->pid = $this->_get('pid');
		}else{
			$this->listmap['pid'] = '0';
			$this->pid = 0;
		}
		$map['id'] = $this->_get('pid');
		$returnid = $this -> dao -> where($map) -> Field('pid')-> find();
		$this->assign('returnid', $returnid['pid']);
		
        parent::_list();
		$list = $this->list;
		$pages = $this->pages;
		$this->imgList();
		$this->assign('list', $list);
		$this->assign('pages', $pages);
		$this->display();
	}
	
	private function imgList(){
		$this->dao = D('Img');
		$this->listmap = "user_id = ".session(C('USER_AUTH_KEY'));
		if(isset($_GET['pid'])){
			$this->listmap .= " and cate_id=".intval($_GET['pid']);
			
		}else{
			$this->listmap .= " and cate_id=0";
		}
		parent::_list();
		$this->assign('imgList',$this->list);
		$this->assign('imgPages', $this->pages);
        
	}
	
	public function add(){
		$this->pid = $this->_get('pid');
		
		parent::add();
	}
	
	public function insert(){
		if($this->_post('is_system')>0){
			if(!session(C('ADMIN_AUTH_KEY'))){
				$this->error('只有开发人员可以建立系统分类');
			}
			$_POST['site_id'] = 0;
			
		}
		$_POST['user_id'] = session(C('USER_AUTH_KEY') );
		parent::insert();
	}
}
